package org.wu.framework.lazy.orm.core.source.clickhouse;

import lombok.Data;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.core.utils.ObjectUtils;
import org.wu.framework.lazy.orm.core.persistence.conf.LazyTableFieldEndpoint;
import org.wu.framework.lazy.orm.core.persistence.conf.field.AbstractLazyTableFieldEndpoint;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;

/**
 * mysql Java字段转换成mysql column对象处理
 */
@Data
public class ClickHouseColumnEndpoint extends AbstractLazyTableFieldEndpoint {


    /**
     * 数据库列类型
     * @return
     */
    @Override
    public String getColumnType() {
        return ObjectUtils.isEmpty(super.getColumnType()) ? LazyTableField.FieldType.getClickHouseTypeByClass(super.getClazz()) : super.getColumnType();
    }
    /**
     * @return 行sql
     * description 创建SQL column
     * id UInt32 COMMENT '这是一个ID字段',
     * @author Jiawei Wu
     * @date 2020/12/31 9:19 下午
     **/
    @Override
    public String columnSQL() {
        return
                NormalUsedString.BACKTICK + getColumnName() + NormalUsedString.BACKTICK + NormalUsedString.SPACE +
                getColumnType() + NormalUsedString.SPACE +
//                (
//                        isNotNull() ?
//                                NormalUsedString.SPACE + NormalUsedString.NOT + NormalUsedString.SPACE + NormalUsedString.NULL + NormalUsedString.SPACE :
//                                NormalUsedString.SPACE
//                ) +
//                (
//                        ObjectUtils.isEmpty(getDefaultValue()) ?
//                                NormalUsedString.SPACE :
//                                NormalUsedString.SPACE + NormalUsedString.DEFAULT + NormalUsedString.SPACE + getDefaultValue() + NormalUsedString.SPACE) +
//                NormalUsedString.SPACE + getExtra() + NormalUsedString.SPACE +
                NormalUsedString.COMMENT + NormalUsedString.SPACE +
                NormalUsedString.SINGLE_QUOTE + getComment() + NormalUsedString.SINGLE_QUOTE;
    }

    @Override
    public LazyTableFieldEndpoint clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
